const Koa = require("./lib/application");
const app = new Koa();

// app.use((req, res) => {
//     res.writeHeader(200, { 'Content-Type': 'application/json'})
//     res.end("hello world 水电费")
// })

app.use(async (ctx, next) => {
    console.log('1');
    await next();
    console.log('6');
})


app.use(async (ctx, next) => {
    console.log('2');
    // 异常捕获错误
    // throw new Error('New Error')
    await next();
    console.log('5');
})

app.use(async ctx => {
    console.log('3');
    ctx.res.setHeader('Content-type','text/html;charset=utf-8')
    ctx.status = 404;
    ctx.body = "服务异常!!! 请联系后端人员"
    console.log('4');
})



app.listen(3001, () => {
    console.log("hello Koa");
})